#include <Windows.h>
#include <iostream>
#include "application/application.h"
#include "gpu/gpu.h"
#pragma comment(linker, "/subsystem:console /entry:wWinMainCRTStartup")

Image* image01 = Image::createImage("assets/testimage.png");
void render() {
	sgl->clear();

	//Point p1{ 100,100, RGBA(0,255,0,255)};
	//Point p2{ 500,600, RGBA(255,0,0,255)};

	//sgl->drawLine(p1, p2);
	
	//Point p1{ 100,100,RGBA(255,0,0,255)};
	//Point p2{ 400,120,RGBA(0,255,0,255)};
	//Point p3{ 400,400,RGBA(0,0,255,255)};

	//sgl->drawTriangle(p1, p2, p3);

	sgl->drawImage(image01);

	//int r = 100;
	//Point c{ 400,300, RGBA(0,0,0,255)};
	//for (float i = 0; i < 360; i += 10) {
	//	float radian = DEG2RAD(i);
	//	int x = r * sin(radian) + c.x;
	//	int y = r * cos(radian) + c.y;
	//	Point pt{ x,y, RGBA(rand()%255,rand()%255,rand()%255,255)};

	//	sgl->drawLine(c, pt);
	//}
	//for (uint32_t i = 0; i < app->getWidth(); i++) {
	//	sgl->drawPoint(i, 100, RGBA(255, 255, 255));
	//}

	//for (uint32_t i = 0; i < app->getWidth(); ++i) {
	//	for (uint32_t j = 0; j < app->getHeight(); ++j) {
	//		uint32_t v1 = std::rand() % 255;
	//		uint32_t v2 = std::rand() % 255;
	//		uint32_t v3 = std::rand() % 255;
	//		uint32_t v4 = std::rand() % 255;
	//		RGBA color(v1, v2, v3, v4);
	//		sgl->drawPoint(i, j, color);
	//	}
	//}
}

int APIENTRY wWinMain(
	_In_ HINSTANCE hInstance,
	_In_opt_ HINSTANCE hPrevInstance,
	_In_ LPWSTR lpCmdLine,
	_In_ int nCmdShow
) {
	if (!app->initApplication(hInstance, 800, 600)) {
		return -1;
	}

	sgl->initSurface(app->getWidth(), app->getHeight(), app->getCanvas());

	bool alive = true;
	while (alive) {
		alive = app->peekMessage();
		render();
		app->show();
	}
	return 0;
}